home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / plnk081.zip / pilot-link.0.8.1 / Python / test.py < prev   
Text File  |  1997-08-09  |  2KB  |  138 lines

  1.  
  2. try:
  3.     import pdapiot
  4. except:
  5.     import sys
  6.     sys.path.append('./.libs/')
  7.     import pdapilot
  8.  
  9. from sys import stdin
  10.  
  11. print 'Please enter the serial port [/dev/cua3]: ',
  12. port = stdin.readline()
  13. port = port[0:len(port)-1]
  14.  
  15. if len(port) == 0:
  16.   port = '/dev/cua3'
  17.  
  18. print 'Using port',port
  19.  
  20. socket = pdapilot.openPort(port)
  21.  
  22. # OpenPort is the equivalent of
  23. #
  24. #socket = pdapilot.socket(pdapilot.PI_AF_SLP, pdapilot.PI_SOCK_STREAM, pdapilot.PI_PF_PADP);
  25. #
  26. #pdapilot.bind(socket, {'family': pdapilot.PI_AF_SLP, 'device': port})
  27. #
  28. #pdapilot.listen(socket,1)
  29.  
  30. print "Now press the HotSync button"
  31.  
  32. dlp = pdapilot.accept(socket)
  33.  
  34. print dlp.getDBInfo(0)
  35.  
  36. ui = dlp.getUserInfo()
  37.  
  38. b = dlp.getBattery()
  39.  
  40. print "Battery voltage is ", b[0], " (warning marker is ", b[1],", critical marker ", b[2], ")\n"
  41.  
  42. rpc = pdapilot.PackRPC(0xA0B6, "i", ("b", "&s", "&s", "&s", "&b", "&b"),
  43.                                     (0,   0,    0,    0,    0,    0))
  44. b = dlp.RPC(rpc)
  45.  
  46. print "Battery results through Python RPC:", b
  47.  
  48. # Looks like this broke. Oh well.
  49. #rpc = pdapilot.PackRPC(0xA220, "i", ("&*", "s", "s", "s"), 
  50. #                                 ("Woo woo!", 8, 100, 0))
  51. #
  52. #dlp.RPC(rpc)
  53.  
  54. print "At open"
  55.  
  56. try:
  57.     db = dlp.open('MailDB')
  58.     
  59.     appinfo = db.getAppBlock()
  60.     
  61.     print 'App block:', appinfo
  62.     
  63.     r = db.getRecord(0)
  64.     
  65.     print 'Record 0:', r
  66.     
  67.     s = db.getPref(1)
  68.  
  69.     print 'Pref 1:', s
  70.     
  71.     s = db.getPref(3)
  72.     
  73.     print 'Pref 3:', s
  74.     
  75.     r = db.getRecord(1)
  76.     
  77.     print 'Record 1:', r
  78.     
  79.     q = db.newPref(1)
  80.     
  81.     print 'Blank pref 1:', q
  82.     
  83.     
  84.     p = dlp.getPref(pdapilot.Mail.creator, 1)
  85.     
  86.     print p
  87.     print "Repacked: ", `p.pack()`
  88.     
  89.     p = dlp.getPref(pdapilot.Mail.creator, 3)
  90.     
  91.     print p
  92.     print "Repacked: ", `p.pack()`
  93.     
  94.     # Construct a blank preference object
  95.     p = dlp.newPref(pdapilot.Mail.creator, 1)
  96.     print p
  97.  
  98.     p = dlp.getPrefRaw(pdapilot.Mail.creator, 1)
  99.     print p
  100.  
  101.     db.close()
  102. except pdapilot.error:
  103.     0
  104.  
  105. db = dlp.open("MemoDB")
  106.  
  107. print "Class: ", db.Class
  108.  
  109. print "At getrecord"
  110.  
  111. r = db.getRecord(0)
  112.  
  113. print "Memo: ", r
  114.  
  115. x = db.newRecord()
  116. x.text = 'a-aFooFoo!'
  117. x.id = None
  118. print x.pack()
  119. print x
  120.  
  121. db.setRecord(x)
  122.  
  123. print "New memo: ", x
  124.  
  125. r = db.getAppBlock()
  126. print "Got app block", r
  127.  
  128. r = db.newAppBlock()
  129.  
  130. print "New app block: ", r
  131.  
  132. del db # Close database
  133.  
  134. del dlp; # Close connection
  135.  
  136. print "Your name is ", ui["name"], "\n";
  137.  
  138.